<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Admin;

class LoginController extends Controller
{
    public function login()
    {
    	return view('hrs.login');
    }

    public function loginDo(Request $request)
    {    	
        $rs['status'] = 'danger';
        $username  = $request->username;
    	$password  = $request->password;

       
        $where['username']  = $username;
       
        
    	$user = Admin::where($where)->first();
        
        //dd($where,$user,md5($password.$user->salt),$user->password);
    	if($user) {
            
    		if(md5($password.$user->salt) == $user->password) {
    			$request->session()->put('admin', $user);                
                return redirect('/');
    		}else{
    			$rs['msg'] = '密码错误';
    		  	return redirect('login')->with('rs',$rs);	
    		}
    	}
    	$rs['msg'] = '用户不存在';
        return redirect('login')->with('rs',$rs);

    }

    public function logOut(Request $request)
    {
        $request->session()->forget('admin');
        return redirect('login');
    }

}
